﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.ResultFormat
{
    /// <summary>
    /// 接口返回数据
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class Result<T>
    {
        /// <summary>
        /// 实际返回数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 执行是否成功
        /// </summary>
        public bool IsSuccess { get; set; }
        /// <summary>
        /// 错误消息
        /// </summary>
        public string Message { get; set; } = "";

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <returns></returns>
        public static Result<T> Success(T data)
        {
            return new Result<T>() { IsSuccess = true, Data = data };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <returns></returns>
        public static Result<T> Error()
        {
            return new Result<T>() { IsSuccess = false };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="errorMsg">错误信息</param>
        /// <returns></returns>
        public static Result<T> Error(string errorMsg)
        {
            return new Result<T>() { IsSuccess = false, Message = errorMsg };
        }
    }
    /// <summary>
    /// 接口返回数据
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    public class Result<T1,T2> : Result
    {
        /// <summary>
        /// 实际返回数据
        /// </summary>
        public T1 Data1 { get; set; }
        /// <summary>
        /// 实际返回数据
        /// </summary>
        public T2 Data2 { get; set; }

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <returns></returns>
        public static Result<T1, T2> Success(T1 data1, T2 data2)
        {
            return new Result<T1, T2>() { IsSuccess = true, Data1 = data1, Data2 = data2 };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <returns></returns>
        public new static Result<T1, T2> Error()
        {
            return new Result<T1, T2>() { IsSuccess = false };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="errorMsg">错误信息</param>
        /// <returns></returns>
        public new static Result<T1, T2> Error(string errorMsg)
        {
            return new Result<T1, T2>() { IsSuccess = false, Message = errorMsg };
        }
    }
    /// <summary>
    /// 接口返回数据
    /// </summary>
    /// <typeparam name="T1"></typeparam>
    /// <typeparam name="T2"></typeparam>
    /// <typeparam name="T3"></typeparam>
    public class Result<T1, T2, T3> : Result
    {
        /// <summary>
        /// 实际返回数据
        /// </summary>
        public T1 Data1 { get; set; }
        /// <summary>
        /// 实际返回数据
        /// </summary>
        public T2 Data2 { get; set; }
        /// <summary>
        /// 实际返回数据
        /// </summary>
        public T3 Data3 { get; set; }

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <returns></returns>
        public static Result<T1, T2, T3> Success(T1 data1, T2 data2, T3 data3)
        {
            return new Result<T1, T2, T3>() { IsSuccess = true, Data1 = data1, Data2 = data2 };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <returns></returns>
        public new static Result<T1, T2, T3> Error()
        {
            return new Result<T1, T2, T3>() { IsSuccess = false };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="errorMsg">错误信息</param>
        /// <returns></returns>
        public new static Result<T1, T2, T3> Error(string errorMsg)
        {
            return new Result<T1, T2, T3>() { IsSuccess = false, Message = errorMsg };
        }
    }

    /// <summary>
    /// 接口返回数据
    /// </summary>
    public class Result
    {
        /// <summary>
        /// 执行是否成功
        /// </summary>
        public bool IsSuccess { get; set; }
        /// <summary>
        /// 错误消息
        /// </summary>
        public string Message { get; set; } = "";

        /// <summary>
        /// 执行成功
        /// </summary>
        /// <returns></returns>
        public static Result Success() 
        {
            return new Result() { IsSuccess = true };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <returns></returns>
        public static Result Error()
        {
            return new Result() { IsSuccess = false };
        }
        /// <summary>
        /// 执行失败
        /// </summary>
        /// <param name="errorMsg">错误信息</param>
        /// <returns></returns>
        public static Result Error(string errorMsg)
        {
            return new Result() { IsSuccess = false , Message = errorMsg };
        }
    }
}
